#include "main.h"
#include "usart.h"
#include "vtor_shell.h"

#ifdef __VTOR_SHELL_STM32F1_HAL__


int VtorShell_Device(int cmd)
{
	// 工程信息
	VtorShell_PrintString("__VTOR_SHELL_STM32F1_HAL__\r\n");
	VtorShell_PrintString("build time "__DATE__" "__TIME__"\r\n\r\n");
	
	// 版本信息
	VtorShell_PrintString("20250220 create vtor_shell_stm32f1_hal\r\n");
	VtorShell_PrintString("\r\n");
	
	// 返回运行时长（ms）
	return HAL_GetTick();;
}

//系统复位  所有电路都会复位
void McuSystemReset(void)
{
	__set_FAULTMASK(1);	 //关闭所有中断
	// 源码见 core_cm3.h 文件 static __INLINE void NVIC_SystemReset(void) 函数
	NVIC_SystemReset();  //系统复位
}

int VtorShell_Add2(int a, int b)
{
	return a + b;
}

const VtorShell VtorShell_demoArray[] =
{
	(VtorShellFun)VtorShell_Icon, "icon",
	(VtorShellFun)VtorShell_Help, "help",
	(VtorShellFun)VtorShell_Void, "void",
	(VtorShellFun)VtorShell_List, "list",
	(VtorShellFun)VtorShell_Int, "int",
	(VtorShellFun)VtorShell_String, "str",
	(VtorShellFun)VtorShell_HexString, "hexstr",
	(VtorShellFun)VtorShell_Call, "call",
	(VtorShellFun)VtorShell_Memory, "mem",
	(VtorShellFun)VtorShell_ReadInt32, "readint32",
	(VtorShellFun)VtorShell_WriteInt32, "writeint32",
	(VtorShellFun)VtorShell_ReadMem, "readmem",
	(VtorShellFun)VtorShell_WriteMem, "writemem",
	
	(VtorShellFun)VtorShell_Device, "dev",
	(VtorShellFun)McuSystemReset, "reset",
	
	
	
	(VtorShellFun)VtorShell_Add2, "add2",
	(VtorShellFun)VtorShell_Void, "void",
	(VtorShellFun)VtorShell_Void, "void",
	(VtorShellFun)VtorShell_Void, "void",
	(VtorShellFun)VtorShell_Void, "void",
	(VtorShellFun)VtorShell_Void, "void",
	(VtorShellFun)VtorShell_Void, "void",
	(VtorShellFun)VtorShell_Void, "void",
	(VtorShellFun)NULL, "",

};



void VtorShell_Init()
{
	VtorShell_shellHeader = (VtorShell*)VtorShell_demoArray;
}


int32_t VtorShell_PrintString(uint8_t* str)
{
	// 方式1，直接串口1输出，不进行重定向
	// return HAL_UART_Transmit(&huart1, str, strlen((char*)str), 0xFF);
	
	// 方式2，使用vtor_string进行输出，需指定通道
	return VtorString_ChanPrintString(5, str);
}


#endif


